package model

import (
	"gitee.com/ling1314/origin-utility/utils"
	"gorm.io/plugin/soft_delete"
)

const (
	DefaultClusterId = 1 // 默认集群ID

	ClusterTimeOutActionForLogout = 1 // 注销会话
	ClusterTimeOutActionForOff    = 2 // 断开会话

	ClusterTypeForPrivate = 1 // 私有集群
	ClusterTypeForPreempt = 2 // 抢占
	ClusterTypeForShare   = 3 // 共享
)

type Cluster struct {
	ClusterId       int64                 `json:"clusterId,string" gorm:"primaryKey"`
	Name            string                `json:"name"`
	CpuThreshold    float64               `json:"cpuThreshold"`
	MemoryThreshold float64               `json:"memoryThreshold"`
	TimeOutAction   int                   `json:"timeOutAction"` // 1-注销会话 ，2-断开会话
	MaxSessionTime  int                   `json:"maxSessionTime"`
	MaxTimeOutTime  int                   `json:"maxTimeOutTime"`
	ClusterType     int                   `json:"clusterType"`
	Creator         string                `json:"creator" gorm:"comment:'创建者'"`
	CreatorId       int64                 `json:"creatorId,string" gorm:"comment:'创建者id'"`
	CreatedAt       int64                 `json:"createdAt,string" gorm:"autoCreateTime"`
	UpdatedAt       int64                 `json:"updatedAt,string" gorm:"autoUpdateTime"`
	DeletedAt       soft_delete.DeletedAt `json:"-"`

	Hosts []AppHost  `json:"hosts" gorm:"-"`
	Apps  []AppIssue `json:"apps" gorm:"-"`
}

func (r *Cluster) TableName() string {
	return "va_clusters"
}

type MoveHostForm struct {
	ClusterId int64                  `json:"clusterId,string"`
	HostIds   utils.StringArrayInt64 `json:"hostIds"`
}

type ClusterForm struct {
	ClusterId       int64   `json:"clusterId,string"`
	Name            string  `json:"name"`
	CpuThreshold    float64 `json:"cpuThreshold"`
	MemoryThreshold float64 `json:"memoryThreshold"`
	TimeOutAction   int     `json:"timeOutAction"`
	MaxSessionTime  int     `json:"maxSessionTime"`
	MaxTimeOutTime  int     `json:"maxTimeOutTime"`
	ClusterType     int     `json:"clusterType"`
}
